package com.fms.gui.templateCreator.components.date.parts;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;

public abstract class Hand
{

	private static final int X = 0;
	private static final int Y = 1;
		
	private BufferedImage imageBuffer;

	public Hand(double width, double height)
	{
		double[] bottomLeft = new double[]{-(width / 2.0), -10.0};
		double[] topLeft = new double[]{-(width / 4.0), height};
		double[] topRight = new double[]{ (width / 4.0), height};
		double[] bottomRight= new double[]{ (width / 2.0), -10.0};
		
		imageBuffer = new BufferedImage((int)width, (int)height, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g2d = (Graphics2D) imageBuffer.getGraphics();

		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                   			 RenderingHints.VALUE_ANTIALIAS_ON);

		GradientPaint gp = new GradientPaint(75, 75, Color.black, 95, 95,
				 							 Color.gray, true);
		g2d.setPaint(gp);
		g2d.translate(width /2.0, 0.0);
		 
		int[] xs = new int[] {(int)bottomLeft[X], (int)bottomRight[X], (int)topRight[X], (int)topLeft[X]};
		int[] ys = new int[] {(int)bottomLeft[Y], (int)bottomRight[Y], (int)topRight[Y], (int)topLeft[Y]};
		 
		g2d.fill(new Polygon(xs, ys, 4));
	}
	
	
	public Hand()
	{
		this(10.0, 100.0);
	}
		
	protected abstract double getAngle();

	public abstract void moveTo(int x, int y);

	public void paint(Graphics graphics)
	{		
		double rotate =  getAngle() + (Math.PI);		
		Graphics2D g2d = (Graphics2D) graphics;
		g2d.transform(AffineTransform.getRotateInstance(rotate));
		g2d.drawImage(imageBuffer, -(int)( imageBuffer.getWidth()/2.0), -10, null);
		g2d.transform(AffineTransform.getRotateInstance(-rotate));
		 
	}
}
